package liu.example.orderserver.controller;

import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import liu.example.serviceapi.UserService;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author: liuchong
 * @create: 2023/2/28 18:46
 * @description:
 */
@RestController
public class OrderController {

    @DubboReference
    private UserService userService;

    @GetMapping("getQuotation")
    public String getQuotation(String data) throws IOException {
        File file = new File("/Users/liuchong/learning-notes/PracticalMicroservives/dubbo_liu_demo/order-server/src/main/java/liu/example/orderserver/controller/quotation_data.txt");
        BufferedWriter bw = new BufferedWriter(new FileWriter(file, true));
        try {
            bw.write(data + System.currentTimeMillis());
            bw.newLine();
            bw.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (bw != null)
                    bw.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        String mes = "";
        mes = userService.getUserById(data);
        return mes;
    }
}
